package nl.science.uva.pico.operator;

import nl.science.uva.pico.Stack;
import nl.science.uva.pico.operand.Operand;

/** 
 * Load pushes a value on the stack 
 * 
 * @author Ivo van Dongen, Karel Pieterson
 * @version 1.0  
 */
public class Load extends Operator {

	public Load(Stack stack) {
		super(stack, null, null);
	}
	
    /**
     *  Load This instruction pushes the value of stack location x on the stack 
     *  (obviously, x should be an integer constant).
     *  The original value is still in its place on the stack; thus Load works like a copy    
     *     
     */	
	@Override
	public void perform() {
		Integer address = getStack().pop().getIntegerValue();
		Operand value = getStack().get(address);
		getStack().push(value);
	}

}
